/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import remoteEntity.Download;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author viktor
 */
@Stateless
public class DownloadFacade extends AbstractFacade<Download> {
    @PersistenceContext(unitName = "filecityeePU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public DownloadFacade() {
        super(Download.class);
    }
    
    public void logDownload(int userId, int downloadId) {
        Download dl = new Download();
        dl.setFiledescriptionId(downloadId);
        dl.setUserId(userId);
        dl.setTimestamp(new Date());
        em.persist(dl);
    }
    
    public List<Download> getDownloadsForUser(int id) {
        return em.createNamedQuery("Download.findByUserId").setParameter("userId", id).getResultList();
    }
}
